package com.jixi.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jixi.common.result.PageResult;
import com.jixi.mapper.StudentMapper;
import com.jixi.pojo.entity.Student;
import com.jixi.pojo.vo.StudentDetailVo;
import com.jixi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 查询管理班级详情
     * */
    @Override
    public PageResult getClassDetail(Integer page, Integer pageSize, Long classId,String date,String studentName,String studentCard) {
        if(date == null || date == ""){
            //获取今日日期
            // 创建一个Date对象（当前日期和时间）
            java.util.Date dateNow = new Date();
            // 创建一个SimpleDateFormat对象，指定日期格式
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
            // 使用SimpleDateFormat的format方法将Date对象转换为String
            String formattedDate = sdf.format(dateNow);
            date = formattedDate;
        }
        Page<StudentDetailVo> setmealInfoVoPage = studentMapper.getClassDetail(new Page<>(page, pageSize), classId,date,studentName,studentCard);
        List<StudentDetailVo> records = setmealInfoVoPage.getRecords();
        PageResult pageResult = new PageResult();
        pageResult.setRecords(records);
        pageResult.setTotal(setmealInfoVoPage.getTotal());
        return pageResult;
    }
    /**
     * 管理学生人数
     * */
    @Override
    public Long getTotalStudents() {
        Long teacherId = StpUtil.getLoginIdAsLong();
        Long totalStudents = studentMapper.getTotalStudents(teacherId);
        return totalStudents;
    }
}
